//
//  LotteryOpenDetailSFCViewController.m
//  PlayBall
//
//  Created by Sun Fanglei on 13-6-7.
//
//

#import "JddLotteryOpenDetailSFCViewController.h"
#import "SBJson.h"

@interface JddLotteryOpenDetailSFCViewController ()

@end

@implementation JddLotteryOpenDetailSFCViewController

SHARED_VIEW_CONTROLLER_IMPLEMENT(JddLotteryOpenDetailSFCViewController);

@synthesize label_1_j;
@synthesize label_1_zhushu;
@synthesize label_2_j;
@synthesize label_2_zhushu;
@synthesize label_3_j;
@synthesize label_3_zhushu;
@synthesize label_enddate;
@synthesize label_issue;
@synthesize label_opendate;
@synthesize label_rx9_xl;
@synthesize label_rx9_yue;
@synthesize label_sfc_xl;
@synthesize label_sfc_yue;
@synthesize h1;
@synthesize h2;
@synthesize h3;
@synthesize h4;
@synthesize h5;
@synthesize h6;
@synthesize h7;
@synthesize h8;
@synthesize h9;
@synthesize h10;
@synthesize h11;
@synthesize h12;
@synthesize h13;
@synthesize h14;

@synthesize s1;
@synthesize s2;
@synthesize s3;
@synthesize s4;
@synthesize s5;
@synthesize s6;
@synthesize s7;
@synthesize s8;
@synthesize s9;
@synthesize s10;
@synthesize s11;
@synthesize s12;
@synthesize s13;
@synthesize s14;

@synthesize v1;
@synthesize v2;
@synthesize v3;
@synthesize v4;
@synthesize v5;
@synthesize v6;
@synthesize v7;
@synthesize v8;
@synthesize v9;
@synthesize v10;
@synthesize v11;
@synthesize v12;
@synthesize v13;
@synthesize v14;

@synthesize issue;
@synthesize realResult;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    customLab.backgroundColor = [UIColor clearColor];
    [customLab setText:PAGE_OPEN_DETAIL];
    customLab.textAlignment = NSTextAlignmentCenter;
    [customLab setTextColor:[UIColor whiteColor]];
    customLab.font = [UIFont systemFontOfSize:19];
    self.navigationItem.titleView = customLab;
    
//    //self.navigationItem.hidesBackButton = YES;
   
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"LotteryOpenSFCdetail"];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"LotteryOpenSFCdetail"];

    SBJsonParser *jsonparser = [[SBJsonParser alloc] init];
    NSDictionary *buydetail = [jsonparser objectWithString:realResult];
    label_issue.text = [NSString stringWithFormat:@"%@期",issue];
    label_opendate.text = [JddCommonFunction getStringDateWithStringDateTime:[buydetail objectForKey:@"EndTime"]];
    label_enddate.text = [JddCommonFunction getOpenEndDateWithEndtime:[buydetail objectForKey:@"EndTime"]];
    NSMutableArray *winNumArray = [[NSMutableArray alloc] initWithCapacity:14];
    NSDictionary *winNum = [buydetail objectForKey:@"Matchs"];
    for (NSDictionary *num in winNum) {
        [winNumArray addObject:[num objectForKey:@"Result"]];
    }
    if ([winNumArray count] == 14) {
        s1.text = [winNumArray objectAtIndex:0];
        s2.text = [winNumArray objectAtIndex:1];
        s3.text = [winNumArray objectAtIndex:2];
        s4.text = [winNumArray objectAtIndex:3];
        s5.text = [winNumArray objectAtIndex:4];
        s6.text = [winNumArray objectAtIndex:5];
        s7.text = [winNumArray objectAtIndex:6];
        s8.text = [winNumArray objectAtIndex:7];
        s9.text = [winNumArray objectAtIndex:8];
        s10.text = [winNumArray objectAtIndex:9];
        s11.text = [winNumArray objectAtIndex:10];
        s12.text = [winNumArray objectAtIndex:11];
        s13.text = [winNumArray objectAtIndex:12];
        s14.text = [winNumArray objectAtIndex:13];
    }
    
    NSDictionary *resultValue = [jsonparser objectWithString:realResult];
    label_sfc_xl.text = [NSString stringWithFormat:@"%@彩豆",[resultValue objectForKey:@"Sales"]];
    label_rx9_xl.text = [NSString stringWithFormat:@"%@彩豆",[resultValue objectForKey:@"R9Sales"]];
//    label_sfc_yue.text = [NSString stringWithFormat:@"%@彩豆",[resultValue objectForKey:@"Balance"]];
    label_rx9_yue.text = [NSString stringWithFormat:@"%@彩豆",[resultValue objectForKey:@"Balance"]];
    
    NSMutableArray *hTArray = [[NSMutableArray alloc] initWithCapacity:14];
    for (NSDictionary *num in winNum) {
        [hTArray addObject:[num objectForKey:@"HTeam"]];
    }
    
    if ([hTArray count] == 14) {
        h1.text = [hTArray objectAtIndex:0];
        h2.text = [hTArray objectAtIndex:1];
        h3.text = [hTArray objectAtIndex:2];
        h4.text = [hTArray objectAtIndex:3];
        h5.text = [hTArray objectAtIndex:4];
        h6.text = [hTArray objectAtIndex:5];
        h7.text = [hTArray objectAtIndex:6];
        h8.text = [hTArray objectAtIndex:7];
        h9.text = [hTArray objectAtIndex:8];
        h10.text = [hTArray objectAtIndex:9];
        h11.text = [hTArray objectAtIndex:10];
        h12.text = [hTArray objectAtIndex:11];
        h13.text = [hTArray objectAtIndex:12];
        h14.text = [hTArray objectAtIndex:13];
    }
    NSMutableArray *vTArray = [[NSMutableArray alloc] initWithCapacity:14];
    for (NSDictionary *num in winNum) {
        [vTArray addObject:[num objectForKey:@"VTeam"]];
    }
    
    if ([vTArray count] == 14) {
        v1.text = [vTArray objectAtIndex:0];
        v2.text = [vTArray objectAtIndex:1];
        v3.text = [vTArray objectAtIndex:2];
        v4.text = [vTArray objectAtIndex:3];
        v5.text = [vTArray objectAtIndex:4];
        v6.text = [vTArray objectAtIndex:5];
        v7.text = [vTArray objectAtIndex:6];
        v8.text = [vTArray objectAtIndex:7];
        v9.text = [vTArray objectAtIndex:8];
        v10.text = [vTArray objectAtIndex:9];
        v11.text = [vTArray objectAtIndex:10];
        v12.text = [vTArray objectAtIndex:11];
        v13.text = [vTArray objectAtIndex:12];
        v14.text = [vTArray objectAtIndex:13];
    }
    NSArray *awads = [resultValue objectForKey:@"Wins"];
    if ([awads count] == 3) {
    NSDictionary *cellvalue0 = [awads objectAtIndex:0];
    NSDictionary *cellvalue1 = [awads objectAtIndex:1];
    NSDictionary *cellvalue2 = [awads objectAtIndex:2];
    label_1_zhushu.text = [[cellvalue0 objectForKey:@"Count"] stringValue];
    label_1_j.text = [cellvalue0 objectForKey:@"Money"];
    
    label_2_zhushu.text = [[cellvalue1 objectForKey:@"Count"] stringValue];
    label_2_j.text = [cellvalue1 objectForKey:@"Money"];
    label_3_zhushu.text = [[cellvalue2 objectForKey:@"Count"] stringValue];
    label_3_j.text = [cellvalue2 objectForKey:@"Money"];
        }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [self setLabel_issue:nil];
    [self setLabel_opendate:nil];
    [self setLabel_enddate:nil];
    [self setLabel_sfc_xl:nil];
    [self setLabel_sfc_yue:nil];
    [self setLabel_rx9_xl:nil];
    [self setLabel_rx9_yue:nil];
    [self setLabel_1_zhushu:nil];
    [self setLabel_2_zhushu:nil];
    [self setLabel_3_zhushu:nil];
    [self setLabel_1_j:nil];
    [self setLabel_2_j:nil];
    [self setLabel_3_j:nil];
    [self setH1:nil];
    [self setH2:nil];
    [self setH3:nil];
    [self setH4:nil];
    [self setH5:nil];
    [self setH6:nil];
    [self setH7:nil];
    [self setH8:nil];
    [self setH9:nil];
    [self setH10:nil];
    [self setH11:nil];
    [self setH12:nil];
    [self setH13:nil];
    [self setH14:nil];
    [self setV1:nil];
    [self setV2:nil];
    [self setV3:nil];
    [self setV4:nil];
    [self setV5:nil];
    [self setV6:nil];
    [self setV7:nil];
    [self setV8:nil];
    [self setV9:nil];
    [self setV10:nil];
    [self setV11:nil];
    [self setV12:nil];
    [self setV13:nil];
    [self setV14:nil];
    [self setS1:nil];
    [self setS2:nil];
    [self setS3:nil];
    [self setS4:nil];
    [self setS4:nil];
    [self setS5:nil];
    [self setS6:nil];
    [self setS7:nil];
    [self setS8:nil];
    [self setS9:nil];
    [self setS10:nil];
    [self setS11:nil];
    [self setS12:nil];
    [self setS13:nil];
    [self setS14:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
